﻿//*************************************************************************
//面向服务的协作式智能交通系统仿真软件SoC-ITSS v2.1 alpha
//发布单位：西北工业大学--巴黎高科MINES机器人与群智能系统联合实验室
//团队负责人：张凯龙 Zhang Kailong
//团队成员：张大方、杨安胜、王敏、谢策、王雨佳、谢尘玉等
//联系我们：kl.zhang@nwpu.edu.cn
//2012-2021
//*************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using CyberCarSimulation.Bean;
using CyberCarSimulation.Algorithm;

//*******************************************************
//
//文件名(File Name):           Intersection.cs
//
//数据表(Tables):              nothing 
//
//          修改理由：         检查错误
//      
//*******************************************************
namespace CyberCarSimulation.RoadModel
{
    class Intersection
    {
        private string ID;                   //路口ID     
        private PointF Point1;               //路口的四个顶点坐标1
        private PointF Point2;               //路口的四个顶点坐标2
        private PointF Point3;               //路口的四个顶点坐标3
        private PointF Point4;               //路口的四个顶点坐标4
        private float Length;                //路口的长度
        private string Shape;                //路口形状
        private string IType;                //路口类型
        private int CriticalNumber;          //路口临界区个数
        private List<Critical> CriticalList; //路口包含的临界区集合

        private List<Lane> EnterIntLaneList = new List<Lane>();     //从该路口进入的车道
        private List<Lane> LeaveIntLaneList = new List<Lane>();     //从该路口离开的车道

        private List<Message> VtoA_Buffer = new List<Message>();  //车辆到Agent的消息缓冲区
        private List<Message> AtoV_Buffer = new List<Message>();  //Agent到车辆的消息缓冲区

        private MultiSCSPrioFIFO_Sche MultiSCSPrioFIFO_Sche;                                //执行当前路口的调度HQEP-SV
        
        private PriorSingleQueueSingleVehicle_Sche PriorSingleQueueSingleVehicle_Sche;      //执行当前路口的调度HWFP-SQ-SV
       
        private MultiSCSFIFO_Sche MultiSCSFIFO_Sche;                                        //执行当前路口的调度FAFP-SV
        private FIFOMultiQueue_Sche FIFOMultiQueue_Sche;                                    //执行当前路口的调度FAFP-MQ
        private FIFOSingleQueue_Sche FIFOSingleQueue_Sche;                                  //执行当前路口的调度FAFP-SQ
        


        private List<string> ReservationLst = new List<string>(); //该路口进入预约线的车辆集合

        //无参构造函数
        public Intersection()
        { 
        }
        
        //构造函数
        //在加载XML时创建的Intersection使用无参构造，此时就要new调度对象Agent
        public Intersection(string ID)
        {
            this.ID = ID;
            this.MultiSCSPrioFIFO_Sche = new MultiSCSPrioFIFO_Sche(ID);
            
            this.MultiSCSFIFO_Sche = new MultiSCSFIFO_Sche(ID);
            this.FIFOMultiQueue_Sche = new FIFOMultiQueue_Sche(ID);
            
            this.PriorSingleQueueSingleVehicle_Sche = new Algorithm.PriorSingleQueueSingleVehicle_Sche(ID);
            this.FIFOSingleQueue_Sche = new FIFOSingleQueue_Sche(ID);
           
        }

        //有参构造函数
        public Intersection(string ID, PointF Point1, PointF Point2, PointF Point3, PointF Point4,
                            float Length, string Shape, string IType, int CriticalNumber,
                            List<Critical> CriticalList)
        {
             this.ID = ID;                   
             this.Point1 = Point1;
             this.Point2 = Point2;
             this.Point3 = Point3;
             this.Point4 = Point4; 
             this.Length = Length;                
             this.Shape = Shape;
             this.IType = IType;                 
             this.CriticalNumber = CriticalNumber;          
             this.CriticalList = CriticalList;            

        }

        //获取路口ID
        public string GetID() {
            return this.ID;
        }

        //设置路口ID
        public void SetID(string ID)
        {
            this.ID = ID;
        }

        //获取路口顶点坐标1
        public PointF GetPoint1() 
        {
            return this.Point1;
        }

        //设置路口顶点坐标1
        public void SetPoint1(PointF Point1)
        {
            this.Point1 = Point1;
        }

        //获取路口顶点坐标2
        public PointF GetPoint2()
        {
            return this.Point2;
        }

        //设置路口顶点坐标2
        public void SetPoint2(PointF Point2)
        {
            this.Point2 = Point2;
        }

        //获取路口顶点坐标3
        public PointF GetPoint3()
        {
            return this.Point3;
        }

        //设置路口顶点坐标3
        public void SetPoint3(PointF Point3)
        {
            this.Point3 = Point3;
        }

        //获取路口顶点坐标4
        public PointF GetPoint4()
        {
            return this.Point4;
        }

        //设置路口顶点坐标1
        public void SetPoint4(PointF Point4)
        {
            this.Point4 = Point4;
        }

        //获取路口长度
        public float GetLength()
        {
            return this.Length;
        }

        //设置路口长度
        public void SetLength(float Length)
        {
            this.Length = Length;
        }

        //获取路口形状
        public string GetShape()
        {
            return this.Shape;
        }

        //设置路口形状
        public void SetShape(string Shape)
        {
            this.Shape = Shape;
        }

        //获取路口类型
        public string GetIType()
        {
            return this.IType;
        }

        //设置路口类型
        public void SetIType(string IType)
        {
            this.IType = IType;
        }

        //获取临界区个数
        public int GetCriticalNumber() 
        {
            return this.CriticalNumber;
        }

        //设置临界区个数
        public void SetCriticalNumber(int CriticalNumber)
        {
            this.CriticalNumber = CriticalNumber;
        }

        //获取路口包含的临界区集合
        public List<Critical> GetCriticalList()
        {
            return this.CriticalList;
        }

        //设置路口包含的临界区集合
        public void SetCriticalList(List<Critical> CriticalList)
        {
            this.CriticalList = CriticalList;
        }

        //获取进入路口的车道集合
        public List<Lane> GetEnterIntLaneList()
        {
            return this.EnterIntLaneList;
        }

        //设置进入路口的车道集合
        public void SetEnterIntLaneList(List<Lane> EnterIntLaneList)
        {
            this.EnterIntLaneList = EnterIntLaneList;
        }

        //获取离开路口的车道集合
        public List<Lane> GetLeaveIntLaneList()
        {
            return this.LeaveIntLaneList;
        }

        //设置离开路口的车道集合
        public void SetLeaveIntList(List<Lane> LeaveIntLaneList)
        {
            this.LeaveIntLaneList = LeaveIntLaneList;
        }

        //获取VtoA的消息
        public List<Message> GetVtoA_Buffer()
        {
            return VtoA_Buffer;
        }

        //设置VtoA的消息
        public void SetVtoA_Buffer(List<Message> VtoA_Buffer)
        {
            this.VtoA_Buffer = VtoA_Buffer;
        }

        //获取AtoV的消息
        public List<Message> GetAtoV_Buffer()
        {
            //List<Message> VtoVBufferCopy = new List<Message>();
            //for (int i = 0; i < this.AtoV_Buffer.Count();i++)
            //{
            //    Message m = this.AtoV_Buffer[i];
            //    VtoVBufferCopy.Add(m);
            //}
            return this.AtoV_Buffer;
        }

        //设置AtoV的消息
        //public void SetAtoV_Buffer(List<Message> AtoV)
        //{
        //    this.AtoV_Buffer = new List<Message>();
        //    for (int i = 0; i < AtoV.Count(); i++)
        //    {
        //        Message m = AtoV[i];
        //        this.AtoV_Buffer.Add(m);
        //    }
        //}
        public void SetAtoV_Buffer(List<Message> AtoV)
        {
            this.AtoV_Buffer = AtoV;
            
        }

        //获取HQEP-SV
        public MultiSCSPrioFIFO_Sche GetMultiSCSPrioFIFO_Sche() 
        {
            return this.MultiSCSPrioFIFO_Sche;
        }

        //设置HQEP-SV
        public void SetMultiSCSPrioFIFO_Sche(MultiSCSPrioFIFO_Sche MultiSCSPrioFIFO_Sche) 
        {
            this.MultiSCSPrioFIFO_Sche = MultiSCSPrioFIFO_Sche;
        }

        
        
    

        
        //获取调度算法HWFP-SQ-SV
        public PriorSingleQueueSingleVehicle_Sche GetPriorSingleQueueSingleVehicle_Sche() 
        {
            return this.PriorSingleQueueSingleVehicle_Sche;
        }

        //设置调度算法HWFP-SQ-SV
        public void SetPriorSingleQueueSingleVehicle_Sche(PriorSingleQueueSingleVehicle_Sche PriorSingleQueueSingleVehicle_Sche)
        {
            this.PriorSingleQueueSingleVehicle_Sche = PriorSingleQueueSingleVehicle_Sche;
        }

        //获取路口调度的算法对象
        public MultiSCSFIFO_Sche GetMultiSCSFIFOSche()
        {
            return this.MultiSCSFIFO_Sche;
        }

        //设置路口调度的算法对象
        public void SetMultiSCSFIFOSche(MultiSCSFIFO_Sche MultiSCSFIFO_Sche)
        {
            this.MultiSCSFIFO_Sche = MultiSCSFIFO_Sche;
        }

        //获取调度算法FIFO-MQ
        public FIFOMultiQueue_Sche GetFIFOMultiQueue_Sche()
        {
            return this.FIFOMultiQueue_Sche;
        }

        //设置调度算法FIFO-MQ
        public void SetFIFOMultiQueue_Sche(FIFOMultiQueue_Sche FIFOMultiQueue_Sche)
        {
            this.FIFOMultiQueue_Sche = FIFOMultiQueue_Sche;
        }

        //获取调度算法FAFP-SQ
        public FIFOSingleQueue_Sche GetFIFOSingleQueue_Sche() 
        {
            return this.FIFOSingleQueue_Sche;
        }

        //设置调度算法FAFP-SQ
        public void SetFIFOSingleQueue_Sche(FIFOSingleQueue_Sche FIFOSingleQueue_Sche) 
        {
            this.FIFOSingleQueue_Sche = FIFOSingleQueue_Sche;
        }


        //获取进入该路口预约线的车辆
        public List<string> GetReservationLst() 
        {
            return this.ReservationLst;
        }
                
        //设置进入该路口预约线的车辆
        public void SetReservationLst(List<string> ReservationLst) 
        {
            this.ReservationLst = ReservationLst;
        }


        //根据临界区ID寻找路口中临界区
        public Critical FindCriticalByID(string ID)
        { 
            Critical FindCritical = new Critical();
            foreach (Critical Critical in this.CriticalList)
            {
                if (Critical.GetID().Equals(ID))
                {
                    FindCritical = Critical;
                }
            }
            return FindCritical;
        }
        
        //根据ID寻找对应的Intersection,这里是中间节点   ID为路口的ID
        public static Intersection FindIntersectionByID(string IntersectionID)
        {
            Intersection inters = new Intersection();
            foreach (Intersection i in MainData.CEIntersectionList)
            {
                if (i.GetID().Equals(IntersectionID))
                {
                    inters = i; 
                }                
            }
            return inters;
        }       


    }
}
